define([ "app", "angular", "services/BaseService" ], function(app, angular) {

	var deps = [ "$http", "BaseService" ];

	function contactsResource($http, BaseService) {
		return initResource($http, BaseService.restfulUrl + "contactsController/");
	}

	var postHeader = {
			"Content-Type" : "application/x-www-form-urlencoded;charset=utf-8"
	};
	
	function initResource($http, contactsUrl) {
		return {
			/**
			 * 上传附件
			 */
			uploadCropImage: function (formData, cropParam) {
                return $http.post("restful/user/saveUserPic?" + $.param(cropParam), formData, {
                    transformRequest: angular.identity,
                    headers: {
                        "Content-Type": undefined
                    },
                    transformResponse: function (data) {
                    	return {
                    		fileId: data
                    	};
                    }
                });
            },
            
			/**
			 * 获取群组列表（带分页）
			 */
            queryGroupList : function(pageNo, pageSize){
				return $http.get(contactsUrl + "queryGroupList");
			},
			
			
			/**
			 * 获取群组列表（带分页）
			 */
			queryGroupByPage : function(pageNo, pageSize){
				return $http.get(contactsUrl + "queryGroupByPage", {
					params: {
                        pageNo: pageNo || 1,
                        pageSize: pageSize || 10
                    }
                });
			},
			
			/**
			 * 新建群组
			 */
			saveOrUpdateGroup : function(group){
				return $http.post(contactsUrl + "saveOrUpdateGroup", angular.toJson(group));
			},
			
			/**
			 * 删除群组
			 */
			delGroup : function(groupIds){
				return $http.post(contactsUrl + "delGroup", {
					groupIds: angular.isArray(groupIds) ? groupIds : [groupIds]
				}, {
					headers : postHeader
				});
			},
			
			/**
			 * 查询群组详情
			 */
			queryGroupById : function(groupId){
				return $http.get(contactsUrl + "queryGroupById", {
					params: {
						groupId: groupId,
						flag: 1,
					}
				});
			},
			

			/**
			 * 新增群组成员
			 */
			addGroupUser : function(groupId, addUserIds){
				return $http.post(contactsUrl + "updateGroupUser", {
					groupId:groupId,
					addUserIds: angular.isArray(addUserIds) ? addUserIds : [addUserIds]
				}, {
					headers : postHeader
				});
			},
			
			/**
			 * 删除群组成员
			 */
			delGroupUser : function(groupId, removeUserIds){
				return $http.post(contactsUrl + "updateGroupUser", {
					groupId:groupId,
					removeUserIds: angular.isArray(removeUserIds) ? removeUserIds : [removeUserIds]
				}, {
					headers : postHeader
				});
			},
			
			/**
			 * 根据用户id获取用户信息
			 */
			getUserByUserId : function(userId){
				return $http.post("restful/user/getUserByUserId", {
					userId:userId
				}, {
					headers : postHeader
				});
			}
		};
	}

	contactsResource.$inject = deps;
	return app.lazy.service("ContactsResource", contactsResource);
});